package com.app.service;

import java.util.List;
import javax.annotation.Resource;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.subject.WebSubject;
import org.springframework.stereotype.Service;
import com.app.dao.UserDao;
import com.app.model.RoleUser;
import com.app.model.User;

@Service
public class UserService {
	@Resource
	private UserDao userDao;
	
	public List<User> findAllByPage(String sql){
		return userDao.findAllByPage(sql);
	}

	public Integer getCount(String sql) {
		return userDao.getCount(sql);
	}

	public void save(User user) {
		userDao.save(user);
	}
	
	public void update(User user) {
		userDao.update(user);
	}
	
	public void delete(Long id) {
		userDao.delete(id);
	}

	public User getById(Long id) {
		return userDao.getById(id);
	}
	
	public RoleUser getRole(Long id) {
		return userDao.getRole(id);
	}

	public Object getRoleList() {
		return userDao.getRoleList();
	}

	public User getByName(String name) {
		return userDao.getByName(name);
	}
	
	public static String getCurrentLoginName() {
		WebSubject ws = (WebSubject) SecurityUtils.getSubject();
		if (ws == null) {
			return "";
		} else {
			return  (String) ws.getPrincipal();
		}
	}
}
